package cn.com.generaldata.os.service.common;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import cn.com.generaldata.os.constant.FilterConstant;
import cn.com.generaldata.os.dao.intf.BaseDAOInterface;
import cn.com.generaldata.os.paging.Filter;
import cn.com.generaldata.os.paging.FilterRule;
import cn.com.generaldata.os.pojo.User;
import cn.com.generaldata.os.pojo.mvc.Report;
import cn.com.generaldata.os.service.impl.web.ReportServiceForWeb;

@Component
public class ReportedDataService {

	@Autowired
	@Qualifier("baseDAO")
	private BaseDAOInterface<User> userDAO;
	
	@Autowired
	@Qualifier("baseDAO")
	private BaseDAOInterface<Report> reportDAO;
	
	@Autowired
	@Qualifier("reportServiceForWeb")
	private ReportServiceForWeb reportService;
	
	@Autowired
	private UserService userService;


	public boolean BusinessInfor(User user, String serviceId, String channelId) {
		String id = "";
		// DataSourseChance data = new DataSourseChance();
		// data.dataChance(channelId);
		if (serviceId.equals("12001")) {
			userService.createUser(user);
		} else if (serviceId.equals("12002")) {
			userService.modifyUser(user);
		}
		return (StringUtils.isNotBlank(id) ? true : false);

	}


	public boolean ReportData(Report report, String serviceId, String channelId) {
		String id = "";
		// DataSourseChance data = new DataSourseChance();
		// data.dataChance(channelId);
		if (serviceId.equals("12003")) {
			reportService.createMVCReport(report);
		} else if (serviceId.equals("12004")) {
			// report.setReportOperatorId(serviceId);
			cn.com.generaldata.os.pojo.Report ReportPojo = reportService.toPersistReport(report);
			// reportService.modifyMVCReport(report);
			reportService.modifyReport(ReportPojo);
		}
		return (StringUtils.isNotBlank(id) ? true : false);
	}


	public Report synchronizationData(Report report, String serviceId) {
		String reportId = report.getReportId();
		Filter filter = new Filter();
		filter.addRule(new FilterRule(FilterConstant.EQUAL, "reportId", reportId));
		reportDAO.update(report);
		return report;
	}

}
